<template>
    <view class="order-state-menu" :class="bigbtn == 1 ? 'bigbtn' : ''" :v-if="configObj">
        <text v-if="item.State == 2" class="btn btn-gray" @click="refuse">拒绝</text>
        <text v-if="item.State == 2" class="btn btn-success-hollow" @click="reception">接收</text>
        <text v-if="item.State == 5" class="btn btn-gray" @click="print">打印面单</text>
        <text v-if="item.State == 3 || item.State == 4" class="btn btn-success-hollow" @click="deliver">发货</text>
        <uni-popup ref="popTip" type="dialog">
            <uni-popup-dialog
                type="text"
                title="温馨提示"
                :content="popTipData.title"
                :before-close="true"
                @close="cancelIt"
                @confirm="doIt"></uni-popup-dialog>
        </uni-popup>
        <uni-popup ref="popReturnTip" type="center" :animation="false">
            <view class="pop-return-box">
                <view class="pop-return-title">
                    <text>请填写拒绝理由</text>
                </view>
                <textarea v-model="remarkdesc" placeholder="请填写拒绝理由" />
                <view class="pop-action">
                    <view @click="remarkClose">取消</view>
                    <view @click="remarkConfirm">确定</view>
                </view>
            </view>
        </uni-popup>
        <uni-popup ref="popReturnTip1" type="center" :animation="false">
            <view class="pop-return-box">
                <view class="pop-return-title">
                    <text>提示</text>
                </view>
                <view class="desc">是否确定接单？</view>
                <view class="pop-action">
                    <view @click="remarkClose1">取消</view>
                    <view @click="remarkConfirm1">确定</view>
                </view>
            </view>
        </uni-popup>
    </view>
</template>

<script>
import { mapMutations } from "vuex"
import storage from "@/uni-sub-base/utils/storage.js"
import { ReceiveBuyOrder } from "@/pages_supplier/service/api/buyOrder.js"
export default {
    components: {},
    props: {
        item: {
            type: Object,
            default: {},
        },
        islist: {
            type: Boolean,
            default: false,
        },
        bigbtn: {
            type: Number,
            default: 0,
        },
    },
    data() {
        return {
            configObj: null,
            popTipData: {
                title: "确定要取消当前订单?",
                type: 0,
            },
            imageList: [],
            remarkdesc: "",
            one: true,
        }
    },
    mounted() {
        //获取商家配置
        let businessFunctionSettingConfig = storage.getCache("businessFunctionSetting")
        if (businessFunctionSettingConfig && businessFunctionSettingConfig != "") {
            this.configObj = businessFunctionSettingConfig
        } else {
            this.configObj = { 14: 0, 30: 0 }
        }
    },
    methods: {
        ...mapMutations(["UP_ORDER_VIEW"]),
        goUrl(url) {
            this.easyGoTo(url)
        },
        deliver() {
            if (this.item.PostType == 0) {
                this.easyGoTo(
                    "/pages_supplier/packet/order/deliverGoodsList?buyOrdId=" +
                        this.item.ID +
                        "&state=" +
                        this.item.State,
                )
            } else {
                this.easyGoTo(
                    "/pages_supplier/packet/order/deliverGoods?buyOrdId=" +
                        this.item.ID +
                        "&ordId=0&state=" +
                        this.item.State,
                )
            }
        },
        refuse() {
            console.log("aaaaaaa")
            this.$refs.popReturnTip.open()
        },
        reception() {
            console.log("bbbbbbbb")
            this.$refs.popReturnTip1.open()
        },
        print() {
            this.easyGoTo("/pages_supplier/packet/outOrder/list?OrderNo=" + this.item.OrderNo)
        },
        remarkClose() {
            this.$refs.popReturnTip.close()
            this.remarkdesc = ""
        },
        remarkClose1() {
            this.$refs.popReturnTip1.close()
        },
        remarkConfirm() {
            //拒绝
            if (this.remarkdesc == "") {
                this.easyToast("请填写拒绝理由")
                return false
            }
            this.$refs.popReturnTip.close()
            let path = "?id=" + this.item.ID + "&checkResult=2&remark=" + this.remarkdesc
            ReceiveBuyOrder(path).then((res) => {
                if (res.State == 1) {
                    setTimeout((e) => {
                        this.upOrderView()
                    }, 500)
                } else {
                    this.easyToast(res.Msg)
                }
            })
        },
        remarkConfirm1() {
            //接收
            if (this.one) {
                this.one = false
                this.$refs.popReturnTip1.close()
                let path = "?id=" + this.item.ID + "&checkResult=1"
                ReceiveBuyOrder(path).then((res) => {
                    if (res.State == 1) {
                        console.log(123123)
                        setTimeout((e) => {
                            this.upOrderView()
                        }, 500)
                        this.one = true
                    } else {
                        this.easyToast(res.Msg)
                        this.one = true
                    }
                })
            }
        },
        doIt() {
            let type = this.popTipData.type
            switch (type) {
                case 0: {
                    //取消订单
                    let param = {
                        orderId: this.item.OrderId,
                    }
                    orderCancel(param).then((res) => {
                        if (res.State == 1) {
                            this.upOrderView()
                        }
                    })
                    break
                }
                case 1: {
                    //确认收货
                    let param = {
                        orderId: this.item.OrderId,
                    }
                    takeOrder(param).then((res) => {
                        if (res.State == 1) {
                            this.upOrderView()
                        }
                    })
                    break
                }
                default:
                    break
            }
            this.cancelIt()
        },
        //显示确认弹窗
        showTip() {
            this.$refs.popTip.open()
        },
        //关闭弹窗
        cancelIt() {
            this.$refs.popTip.close()
        },
        //更新订单列表
        upOrderView() {
            console.log(454545)
            this.UP_ORDER_VIEW(new Date().getTime())
        },
    },
}
</script>

<style lang="scss">
.order-state-menu {
    display: flex;
    flex-direction: row;
    justify-content: flex-end;

    .btn {
        margin-left: $app-page-padding;
        height: 58rpx;
        font-size: 24rpx;
        min-width: 100rpx;
    }
    .btn-gray {
        border-color: #222a42;
        color: #222a42;
    }
}
.bigbtn {
    flex: 1;
    justify-content: center;
    .btn {
        width: 304rpx;
        height: 80rpx;
        background: $app-color-main;
        margin: 0;
        border-radius: 40rpx;
        padding: 0;
        font-size: 28rpx;
        margin: 0 24rpx;
        color: #ffffff;
    }
    .btn-gray {
        background: #ffffff;
        border: 1rpx solid $app-color-main;
        color: $app-color-main;
    }
}
</style>
